package cn.wolfcode.util;

import cn.wolfcode.domain.Employee;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

public class UserContext {
   /* private static final String USER_IN_SESSION ="USER_IN_SESSION";
    private static final String EXPRESSION_IN_SESSION ="EXPRESSION_IN_SESSION";*/

    //从shiro中获取当前登录用户
    public static Employee getCurrentUser() {
        return (Employee) SecurityUtils.getSubject().getPrincipal();
    }
        /*//springmvc提供的工具,可以在任意地方获取到request对象,response对象,session对象
        ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return attrs.getRequest().getSession();
    }

    //从session中获取当前登录用户
    public static Employee getCurrentUser(){
        return (Employee) getSession().getAttribute(USER_IN_SESSION);
    }
    
    //设置当前登录用户到session中
    public static void setCurrentUser(Employee employee){
        getSession().setAttribute(USER_IN_SESSION,employee);
    }

    //从session中获取当前登录用户的权限表达式集合
    public static List<String> getExpressions(){
        return (List<String>) getSession().getAttribute("EXPRESSION_IN_SESSION");
    }

    //设置当前登录用户的权限表达式集合到session中
    public static void setExpression(List<String> list){
        getSession().setAttribute("EXPRESSION_IN_SESSION",list);
    }*/
}
